<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置变量的类型</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.serialize.html">serialize</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strval.html">strval</a></div>
 <div class="up"><a href="ref.var.html">Variable handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.settype" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">settype</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">settype</span> &mdash; <span class="dc-title">设置变量的类型</span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.settype-description">
  <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="type">bool</span> <span class="methodname"><strong>settype</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter reference">&$var</code></span>
      , <span class="methodparam"><span class="type">string</span> <code class="parameter">$type</code></span>
      )</div>

    <p class="para rdfs-comment">
     将变量 <em><code class="parameter">var</code></em> 的类型设置成
     <em><code class="parameter">type</code></em>。
    </p>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.settype-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">var</code></em></dt>

     <dd>

      <p class="para">
       要转换的变量。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">type</code></em></dt>

     <dd>

      <p class="para">
       <em><code class="parameter">type</code></em> 的可能值为：
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
        “boolean” （或为“bool”，从 PHP 4.2.0 起）
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
        “integer” （或为“int”，从 PHP 4.2.0 起）
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
        “float” （只在 PHP 4.2.0 之后可以使用，对于旧版本中使用的“double”现已停用）
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          &quot;string&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          &quot;array&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          &quot;object&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
        “null” （从 PHP 4.2.0 起）
         </span>
        </li>
       </ul>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.settype-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.settype-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5159">
    <p><strong>Example #1 <span class="function"><strong>settype()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"5bar"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;string<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;boolean<br /><br /></span><span style="color: #0000BB">settype</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"integer"</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;$foo&nbsp;现在是&nbsp;5&nbsp;&nbsp;&nbsp;(integer)<br /></span><span style="color: #0000BB">settype</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"string"</span><span style="color: #007700">);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;$bar&nbsp;现在是&nbsp;"1"&nbsp;(string)<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.settype-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Maximum value for &quot;int&quot; is <strong><code>PHP_INT_MAX</code></strong>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.settype-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.gettype.html" class="function" rel="rdfs-seeAlso">gettype()</a> - 获取变量的类型</span></li>
    <li class="member"><a href="language.types.type-juggling.html#language.types.typecasting" class="link">类型转换</a></li>
    <li class="member"><a href="language.types.type-juggling.html" class="link">类型戏法</a></li>
   </ul>
  </p>
 </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.serialize.html">serialize</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strval.html">strval</a></div>
 <div class="up"><a href="ref.var.html">Variable handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
